<?php
/**
 * Created by PhpStorm.
 * Date: 2020/9/4
 * Time: 18:36
 */

namespace utils;
use utils\upload\Upload;

class UploadService
{
    /**
     * @var array
     */
    protected static $upload = [];

    /**
     * @param $type
     * @return Upload
     */
    public static function init($type = null)
    {
        if (is_null($type)) {
            $type = (int)config('filesystem.upload_type');
        }
        if (isset(self::$upload['upload_' . $type])) {
            return self::$upload['upload_' . $type];
        }
        $type = (int)$type;
        $config = [];
        switch ($type) {
            case 2://七牛
                $config = [
                    'accessKey' => config('qiniu.qiniu_accessKey'),
                    'secretKey' => config('qiniu.qiniu_secretKey'),
                    'uploadUrl' => config('qiniu.qiniu_uploadUrl'),
                    'storageName' => config('qiniu.qiniu_storage_name'),
                    'storageRegion' => config('qiniu.qiniu_storage_region'),
                ];
                break;
            case 3:// oss 阿里云
                $config = [
                    'accessKey' => config('accessKey'),
                    'secretKey' => config('secretKey'),
                    'uploadUrl' => config('uploadUrl'),
                    'storageName' => config('storage_name'),
                    'storageRegion' => config('storage_region'),
                ];
                break;
            case 4:// cos 腾讯云
                $config = [
                    'accessKey' => config('tengxun_accessKey'),
                    'secretKey' => config('tengxun_secretKey'),
                    'uploadUrl' => config('tengxun_uploadUrl'),
                    'storageName' => config('tengxun_storage_name'),
                    'storageRegion' => config('tengxun_storage_region'),
                ];
                break;
        }
        return self::$upload['upload_' . $type] = new Upload($type, $config);
    }

}
